public class ThreadDemo4 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(() -> {
            int a = 10;
            synchronized (object) {
                while (a > 0) {
                    try {
                        System.out.print('A');
                        a--;
                        object.wait();
                        object.notify();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t1.start();
        Thread t2 = new Thread(() -> {
            int a = 10;
            synchronized (object) {
                while (a > 0) {
                    try {
                        System.out.print('B');
                        a--;
                        object.wait();
                        object.notify();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t2.start();
        Thread t3 = new Thread(() -> {
            int a = 10;
            synchronized (object) {
                while (a > 0) {
                    try {
                        System.out.println('C');
                        a--;
                        object.notify();
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t3.start();
    }
}
